﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyRead.API.Appicant.Command.RoleCommand;
using B.S.DataBase.MyRead.API.Appicant.Command.UserCommand;
using B.S.DataBase.MyRead.API.DTOs;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyRead.API.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MessageController : ControllerBase
    {
        private readonly IMediator mediator;

        public MessageController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<User>> Login([FromQuery] LoginCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 查询用户列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<UserDTOs>>> GetUser([FromQuery] GetUserCommand request)
        {
            return await mediator.Send(request);
        }


        /// <summary>
        /// 用户名称唯一
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<object>> OneUserName([FromQuery] OnenessUserNameCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 反填用户单表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<APIResult<User>> FanTianUser([FromQuery] GetFanTianUserCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 部门id查询名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<APIResult<List<User>>> GetDepUserName([FromQuery] DepUserNameCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 角色显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        [HttpGet]
        public Task<APIResult<List<Role>>> GetRole([FromQuery] GetRoleCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 角色名称唯一验证
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<object>> OneRoleName([FromQuery] OnenessRoleNameCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 角色反填(id查询)
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<Role>> RoleFanTian([FromQuery] RoleFanTianCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 根据部门Id查询用户名称
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<User>>> GetUserName([FromQuery] GetDepIdUserCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 通过角色ID查询用户名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<UserNameDTOs>>> GetUserNameRoleId([FromQuery] GetUserNameRoleidCommand request)
        {
            return mediator.Send(request);
        }


    }
}
